package com.ricchieri.service;

import java.io.Serializable;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.ricchieri.common.BusinessSettings;
import com.ricchieri.dao.interf.IScheduleCharterDao;
import com.ricchieri.filter.ScheduleCharterFilter;
import com.ricchieri.model.Reservation;
import com.ricchieri.model.ScheduleCharter;
import com.ricchieri.service.interf.IScheduleCharterService;

@Transactional(readOnly = true)
public class ScheduleCharterService implements IScheduleCharterService, Serializable {
	private static final long serialVersionUID = -616823706626787051L;
	IScheduleCharterDao scheduleCharterDao;
	
	@Override
	@Transactional(readOnly = true)
	public List<ScheduleCharter> getAllScheduleCharter() {
		ScheduleCharterFilter filter = new ScheduleCharterFilter();
		return scheduleCharterDao.getAllScheduleCharter(filter);
	}

	public IScheduleCharterDao getScheduleCharterDao() {
		return scheduleCharterDao;
	}

	public void setScheduleCharterDao(IScheduleCharterDao scheduleCharterDao) {
		this.scheduleCharterDao = scheduleCharterDao;
	}
	
	@Transactional(readOnly = false)
	public void insertScheduleCharter(ScheduleCharter scheduleCharter) {
		scheduleCharterDao.add(scheduleCharter);
	}
	
	@Override
	public List<ScheduleCharter> getAllScheduleCharterPaginatedByFilter(ScheduleCharterFilter charterFilter) {
		return scheduleCharterDao.getAllScheduleCharterPaginatedByFilter(charterFilter);
	}
	
	@Transactional(readOnly = false)
	public void updateScheduleCharter(ScheduleCharter scheduleCharter) {
		scheduleCharterDao.update(scheduleCharter);
	}

	@Override
	@Transactional(readOnly = false)
	public void delete(ScheduleCharter scheduleCharter) {
		scheduleCharter.setActive(Boolean.FALSE);
		scheduleCharter.getSchedule().setActive(Boolean.FALSE);
		
		for (Reservation reservation : scheduleCharter.getActiveReservations()) {
			reservation.setActive(BusinessSettings.ENTITY_INACTIVE);
		}
		
		scheduleCharterDao.update(scheduleCharter);		
	}

	@Override
	public List<ScheduleCharter> getAllScheduleCharterPaginatedByFilter(
			ScheduleCharterFilter charterFilter, int startRecord) {
		return scheduleCharterDao.getAllScheduleCharterPaginatedByFilter(charterFilter, startRecord);
	}

	@Override
	public int getAllScheduleCharterCountByFilter(
			ScheduleCharterFilter charterFilter) {
		return scheduleCharterDao.getAllScheduleCharterCountByFilter(charterFilter);
	}

	@Override
	public ScheduleCharter getScheduleCharterByFilter(
			ScheduleCharterFilter filter) {
		return scheduleCharterDao.getScheduleCharterByFilter(filter);
	}

	@Override
	@Transactional(readOnly = true)
	public List<ScheduleCharter> getAllScheduleCharterByFilter(
			ScheduleCharterFilter charterFilter) {
		return scheduleCharterDao.getAllScheduleCharter(charterFilter);
	}
}
